package com.hanhai.material.device.controller;

import com.alibaba.fastjson.JSONObject;
import com.hanhai.material.common.result.Result;
import com.hanhai.material.common.result.ResultTool;
import com.hanhai.material.device.entity.SysProductRecordDetention;
import com.hanhai.material.device.entity.SysProductRecordDetentionRecord;
import com.hanhai.material.device.entity.SysProductRecordInto;
import com.hanhai.material.device.service.SysProductRecordDetentionRecordService;
import com.hanhai.material.device.service.SysProductRecordDetentionService;
import com.hanhai.material.device.utils.kingdee.TransferDataUtil;
import com.hanhai.material.utils.jiandaoyun.PushToJianDaoYunUtil1;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.hanhai.material.device.entity.table.SysProductRecordDetentionRecordTableDef.SYS_PRODUCT_RECORD_DETENTION_RECORD;
import static com.hanhai.material.device.entity.table.SysProductRecordDetentionTableDef.SYS_PRODUCT_RECORD_DETENTION;
import static com.hanhai.material.utils.TimeUtils.fromDateToString;
import static com.mybatisflex.core.query.QueryMethods.distinct;
import static com.mybatisflex.core.query.QueryMethods.sum;

/**
 * 控制层。
 *
 * @author youchuang
 * @since 2024/01/30 14:06:26
 */
@RestController
@RequestMapping("/product_record_detention")
@Log4j2
public class SysProductRecordDetentionController {

    @Autowired
    private SysProductRecordDetentionService sysProductRecordDetentionService;

    @Autowired
    private SysProductRecordDetentionRecordService sysProductRecordDetentionRecordService;

    @Autowired
    private TransferDataUtil transferDataUtil;

    @Autowired
    private PushToJianDaoYunUtil1 pushToJianDaoYunUtil1;

    /**
     * 添加。
     *
     * @param sysProductRecordDetention
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    public Result<?> save(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        boolean result = sysProductRecordDetentionService.save(sysProductRecordDetention);
        return result ? ResultTool.success() : ResultTool.fail();
    }


    /**
     * 根据主键删除。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    public Result<?> remove(@PathVariable Serializable id) {
        boolean result = sysProductRecordDetentionService.removeById(id);
        return result ? ResultTool.success() : ResultTool.fail();

    }


    /**
     * 根据主键更新。
     *
     * @param sysProductRecordInto
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PostMapping("update")
    public Result<?> update(@RequestBody SysProductRecordInto sysProductRecordInto) {
        List<SysProductRecordDetentionRecord> addProductRecordDetentionRecordList = new ArrayList<>();
        List<SysProductRecordDetentionRecord> updateProductRecordDetentionRecordList = new ArrayList<>();
        List<SysProductRecordDetention> sysProductRecordDetentionList = sysProductRecordInto.getProductRecordDetentionList();
        List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordLists=new ArrayList<>();
        for (SysProductRecordDetention sysProductRecordDetention : sysProductRecordDetentionList) {
            log.error("sysProduct:{}",JSONObject.toJSONString(sysProductRecordDetention));
            if (sysProductRecordDetention.getNum() > 0) {
                sysProductRecordDetention.setStatus(1);
            } else {
                sysProductRecordDetention.setStatus(2);
            }

            if (sysProductRecordDetention.getProductRecordDetentionRecord() != null) {
                SysProductRecordDetentionRecord sysProductRecordDetentionRecord = sysProductRecordDetention.getProductRecordDetentionRecord();
                if (sysProductRecordDetentionRecord.getNum() > 0) {
                    log.error("SysProductRecord:{}", JSONObject.toJSONString(sysProductRecordDetentionRecord));
                    sysProductRecordDetentionRecord.setProductRecordIntoId(sysProductRecordInto.getId());
                    sysProductRecordDetentionRecord.setNowNum(sysProductRecordDetention.getNum());
                    sysProductRecordDetentionRecord.setProductRecordDetentionId(sysProductRecordDetention.getId());
                    sysProductRecordDetentionRecord.setProductName(sysProductRecordDetention.getProductName());
                    sysProductRecordDetentionRecord.setShortName(sysProductRecordDetention.getShortName());
                    sysProductRecordDetentionRecord.setProductRecordId(sysProductRecordDetention.getProductRecordId());
                    sysProductRecordDetentionRecord.setShift(sysProductRecordInto.getShift());
                    sysProductRecordDetentionRecord.setGoodNum(sysProductRecordDetention.getGoodNum());
                    sysProductRecordDetentionRecord.setBadNum(sysProductRecordDetention.getBadNum());
                    sysProductRecordDetentionRecord.setProductDateInto(sysProductRecordInto.getProductDate());
                    sysProductRecordDetentionRecord.setMachineArea(sysProductRecordDetention.getMachineArea());
                    sysProductRecordDetentionRecord.setGroupName(sysProductRecordDetention.getGroupName());
                    sysProductRecordDetentionRecord.setLineManager(sysProductRecordDetention.getLineManager());
                    sysProductRecordDetentionRecord.setLine(sysProductRecordDetention.getLineManager());
                    log.error("SysProductRecord1:{}", JSONObject.toJSONString(sysProductRecordDetentionRecord));

                    if (sysProductRecordDetentionRecord.getId() != null) {
                        updateProductRecordDetentionRecordList.add(sysProductRecordDetentionRecord);
                    } else {
                        sysProductRecordDetentionRecord.setId(UUID.randomUUID().toString());
                        addProductRecordDetentionRecordList.add(sysProductRecordDetentionRecord);
                    }

                }
                sysProductRecordDetentionRecordLists.add(sysProductRecordDetentionRecord);
            }
        }

        log.error("sysProductRecordDetentionList:{}", JSONObject.toJSONString(sysProductRecordDetentionRecordLists));
        log.error("updateProductRecordDetentionRecordList:{}", JSONObject.toJSONString(updateProductRecordDetentionRecordList));
        log.error("addProductRecordDetentionRecordList:{}", JSONObject.toJSONString(addProductRecordDetentionRecordList));
        if (sysProductRecordDetentionRecordLists.size() > 0) {
//            this.sysProductRecordDetentionService.updateBatch(sysProductRecordDetentionList);
        }
        if (addProductRecordDetentionRecordList.size() > 0) {
            this.sysProductRecordDetentionRecordService.saveBatch(addProductRecordDetentionRecordList);

        }
        if (updateProductRecordDetentionRecordList.size() > 0) {
            this.sysProductRecordDetentionRecordService.updateBatch(updateProductRecordDetentionRecordList);
        }
        if (sysProductRecordDetentionRecordLists.size() > 0 ) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO.eq(fromDateToString("yyyy-MM-dd",sysProductRecordInto.getProductDate())));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_ID.eq(sysProductRecordInto.getProductId()));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.GROUP_NAME.eq(sysProductRecordInto.getGroupName()));
            queryWrapper.select(distinct(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_ID).as("product_id"), SYS_PRODUCT_RECORD_DETENTION_RECORD.MACHINE_NAME, SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO, SYS_PRODUCT_RECORD_DETENTION_RECORD.LINE_MANAGER);
            queryWrapper.groupBy(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO, SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_ID, SYS_PRODUCT_RECORD_DETENTION_RECORD.LINE_MANAGER);
            List<SysProductRecordDetentionRecord> productRecordDetentionRecords = this.sysProductRecordDetentionRecordService.list(queryWrapper);
            log.error("Li:{}",JSONObject.toJSONString(productRecordDetentionRecords));
            for (SysProductRecordDetentionRecord productRecordDetentionRecord : productRecordDetentionRecords) {
                queryWrapper = new QueryWrapper();
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_ID.eq(productRecordDetentionRecord.getProductId()));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO.eq(fromDateToString("yyyy-MM-dd",productRecordDetentionRecord.getProductDateInto())));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.LINE_MANAGER.eq(productRecordDetentionRecord.getLineManager()));
                List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordList = this.sysProductRecordDetentionRecordService.getMapper().selectListWithRelationsByQuery(queryWrapper);
                sysProductRecordDetentionRecordList = sysProductRecordDetentionRecordList.stream().filter(item -> item.getProductRecordDetention().getType().equals("待加工")).collect(Collectors.toList());
                List<SysProductRecordDetentionRecord> addList=sysProductRecordDetentionRecordList.stream().filter(item->item.getDataId()==null).collect(Collectors.toList());
                List<SysProductRecordDetentionRecord> updateList=sysProductRecordDetentionRecordList.stream().filter(item->item.getDataId()!=null).collect(Collectors.toList());
                if(addList.size()>0){
                    log.error("List:{}", JSONObject.toJSONString(addList));
                    int goodNumPeople = addList.stream().filter(item -> item.getType().equals("良品")).mapToInt(SysProductRecordDetentionRecord::getNum).sum();
                    int badNumPeople = addList.stream().filter(item -> item.getType().equals("不良品")).mapToInt(SysProductRecordDetentionRecord::getNum).sum();
                    SysProductRecordDetentionRecord sysProductRecordDetentionRecord = addList.get(0);
                    sysProductRecordDetentionRecord.setGoodNumPeople(goodNumPeople);
                    sysProductRecordDetentionRecord.setBadNumPeople(badNumPeople);
                    sysProductRecordDetentionRecord.setNum(goodNumPeople + badNumPeople);
                    String dataId = this.pushToJianDaoYunUtil1.pushToJianDaoYunSingle1(sysProductRecordDetentionRecord);
                    log.error("DataId:{}", dataId);
                    addList.stream().forEach(item->item.setDataId(dataId));
                    this.sysProductRecordDetentionRecordService.updateBatch(addList);
                }
                if(updateList.size()>0){
                    log.error("List:{}", JSONObject.toJSONString(addList));
                    int goodNumPeople = updateList.stream().filter(item -> item.getType().equals("良品")).mapToInt(SysProductRecordDetentionRecord::getNum).sum();
                    int badNumPeople = updateList.stream().filter(item -> item.getType().equals("不良品")).mapToInt(SysProductRecordDetentionRecord::getNum).sum();
                    SysProductRecordDetentionRecord sysProductRecordDetentionRecord = updateList.get(0);
                    sysProductRecordDetentionRecord.setGoodNumPeople(goodNumPeople);
                    sysProductRecordDetentionRecord.setBadNumPeople(badNumPeople);
                    sysProductRecordDetentionRecord.setNum(goodNumPeople + badNumPeople);
                    String dataId = this.pushToJianDaoYunUtil1.updateToJianDaoYunSingle1(sysProductRecordDetentionRecord);
                    log.error("DataId:{}", dataId);
                    updateList.stream().forEach(item->item.setDataId(dataId));
                    this.sysProductRecordDetentionRecordService.updateBatch(updateList);

                }

            }
        }
        return ResultTool.success();
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @PostMapping("list")
    public Result<?> list(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        log.error("SysProductRecordDetention:{}", JSONObject.toJSONString(sysProductRecordDetention));
        if (sysProductRecordDetention.getMachineName() != null) {
            QueryWrapper queryWrapper = QueryWrapper.create();
//            queryWrapper.select(SYS_PRODUCT_RECORD_DETENTION.ID,SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE,SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID,SYS_PRODUCT_RECORD_DETENTION.WORK_PLAN_ID,SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME,SYS_PRODUCT_RECORD_DETENTION.CREATE_USER_NAME,
//                    SYS_PRODUCT_RECORD_DETENTION.TYPE,SYS_PRODUCT_RECORD_DETENTION.REASON,SYS_PRODUCT_RECORD_DETENTION.NUM,SYS_PRODUCT_RECORD_DETENTION.SHIFT);

            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID.eq(sysProductRecordDetention.getProductId()));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.SHIFT.eq(sysProductRecordDetention.getShift()));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME.eq(sysProductRecordDetention.getMachineName()));
//            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.STATUS.ne(2));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.TOTAL_NUM.gt(0));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE.eq(fromDateToString("yyyy-MM-dd", sysProductRecordDetention.getProductDate())));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.SHIFT.eq(sysProductRecordDetention.getShift()));
            queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.CREATE_TIME, true);
//        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION)
            List<SysProductRecordDetention> sysProductRecordDetentionList = this.sysProductRecordDetentionService.list(queryWrapper);
            return sysProductRecordDetentionList.isEmpty() ? ResultTool.fail() : ResultTool.success(sysProductRecordDetentionList);
        } else {
            return ResultTool.fail();
        }
    }

    @PostMapping("list1")
    public Result<?> list1(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        if (sysProductRecordDetention.getMachineName() != null) {
            QueryWrapper queryWrapper = QueryWrapper.create();
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID.eq(sysProductRecordDetention.getProductId()));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME.eq(sysProductRecordDetention.getMachineName()));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE.lt(fromDateToString("yyyy-MM-dd", sysProductRecordDetention.getProductDate())));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.NUM.gt(0));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.LINE_MANAGER.eq(sysProductRecordDetention.getLineManager()));
            queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.CREATE_TIME, true);
            List<SysProductRecordDetention> sysProductRecordDetentionList = this.sysProductRecordDetentionService.list(queryWrapper);

            return sysProductRecordDetentionList.isEmpty() ? ResultTool.fail() : ResultTool.success(sysProductRecordDetentionList);
        } else {
            return ResultTool.fail();
        }
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    public SysProductRecordDetention getInfo(@PathVariable Serializable id) {
        return sysProductRecordDetentionService.getById(id);
    }

    /**
     * 分页查询。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    public Page<SysProductRecordDetention> page(Page<SysProductRecordDetention> page) {
        return sysProductRecordDetentionService.page(page);
    }

    @PostMapping("/allListByType")
    public Result<?> allDataList(@RequestBody SysProductRecordDetention productRecordDetention) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (productRecordDetention.getType() != null) {
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.TYPE.eq(productRecordDetention.getType()));
        }
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE.between(fromDateToString("yyyy-MM-dd",productRecordDetention.getStartDate()), fromDateToString("yyyy-MM-dd",productRecordDetention.getEndDate())));
        queryWrapper.select(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME, SYS_PRODUCT_RECORD_DETENTION.SHIFT, sum(SYS_PRODUCT_RECORD_DETENTION.TOTAL_NUM).as("total_num"),sum(SYS_PRODUCT_RECORD_DETENTION.NUM).as("num"));
        queryWrapper.groupBy(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME, true);
        List<SysProductRecordDetention> sysProductRecordDetentions = this.sysProductRecordDetentionService.list(queryWrapper);
        log.error("SQL:{}", queryWrapper.toSQL());
        for (SysProductRecordDetention sysProductRecordDetention : sysProductRecordDetentions) {
            queryWrapper = QueryWrapper.create();
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE.between(fromDateToString("yyyy-MM-dd",productRecordDetention.getStartDate()), fromDateToString("yyyy-MM-dd",productRecordDetention.getEndDate())));
            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.MACHINE_NAME.eq(sysProductRecordDetention.getMachineName()));
            queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE, true);
            if (productRecordDetention.getType() != null) {
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.TYPE.eq(productRecordDetention.getType()));
            }
            List<SysProductRecordDetention> productRecordDetentionList = this.sysProductRecordDetentionService.getMapper().selectListWithRelationsByQuery(queryWrapper);
            int handleTotal=0;
            for(SysProductRecordDetention productRecordDetention1:productRecordDetentionList){
                productRecordDetention1.setName(fromDateToString("yyyy-MM-dd",productRecordDetention1.getProductDate())+"("+productRecordDetention1.getShift()+")");
                handleTotal+=productRecordDetention1.getTotalNum()-productRecordDetention1.getNum();
//                for(SysProductRecordDetentionRecord productRecordDetentionRecord:productRecordDetention1.getProductRecordDetentionRecordList()){
//                    productRecordDetentionRecord.setName(fromDateToString("yyyy-MM-dd",productRecordDetentionRecord.getProductDate())+"("+productRecordDetentionRecord.getShift()+")");
//                    handleTotal+=productproductRecordDetentionRecord.getNum();
//                }
            }
            sysProductRecordDetention.setHandleTotal(handleTotal);
            sysProductRecordDetention.setChildren(productRecordDetentionList);
        }
        return sysProductRecordDetentions.isEmpty() ? ResultTool.fail() : ResultTool.success(sysProductRecordDetentions);
    }

    @PostMapping("/getProductIdList")
    public Result<?> getProductIdList(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.GROUP_NAME.eq(sysProductRecordDetention.getGroupName()));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.STATUS.ne(2));
        queryWrapper.select(distinct(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID));
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID, true);
        List<SysProductRecordDetention> sysProductRecordDetentionList = this.sysProductRecordDetentionService.list(queryWrapper);
        log.error("SQL:{}",queryWrapper.toSQL());
        return sysProductRecordDetentionList.isEmpty() ? ResultTool.fail() : ResultTool.success(sysProductRecordDetentionList);
    }

    @PostMapping("/getProductRecordDetentionList")
    public Result<?> getProductRecordDetentionList(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.TOTAL_NUM.gt(0));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID.eq(sysProductRecordDetention.getProductId()));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.LINE_MANAGER.eq(sysProductRecordDetention.getLineManager()));

//        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.SHIFT.eq(sysProductRecordDetention.getShift()));
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE, true);
        List<SysProductRecordDetention> sysProductRecordDetentionList = this.sysProductRecordDetentionService.list(queryWrapper);
        List<SysProductRecordDetention> productRecordDetentionList = new ArrayList<>();
        if (!sysProductRecordDetentionList.isEmpty()) {
            for (SysProductRecordDetention productRecordDetention : sysProductRecordDetentionList) {
                queryWrapper = QueryWrapper.create();

                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_RECORD_DETENTION_ID.eq(productRecordDetention.getId()));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO.eq(fromDateToString("yyyy-MM-dd",sysProductRecordDetention.getProductDate())));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.LINE_MANAGER.eq(sysProductRecordDetention.getLineManager()));
//                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.SHIFT.eq(productRecordDetention.getShift()));
                queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION_RECORD.CREATE_TIME, false);
                log.error("SQL:{}", queryWrapper.toSQL());
                List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordList = this.sysProductRecordDetentionRecordService.list(queryWrapper);
                if (sysProductRecordDetentionRecordList.size() > 0) {
                    List<SysProductRecordDetention> productRecordDetentionList1 = new ArrayList<>();
                    for (int j = 0; j < sysProductRecordDetentionRecordList.size(); j++) {
                        SysProductRecordDetention sysProductRecordDetention1 = new SysProductRecordDetention();
                        sysProductRecordDetention1.setId(productRecordDetention.getId());
                        sysProductRecordDetention1.setProductDate(productRecordDetention.getProductDate());
                        sysProductRecordDetention1.setWorkPlanId(productRecordDetention.getWorkPlanId());
                        sysProductRecordDetention1.setProductId(productRecordDetention.getProductId());
                        sysProductRecordDetention1.setShortName(productRecordDetention.getShortName());
                        sysProductRecordDetention1.setProductName(productRecordDetention.getProductName());
                        sysProductRecordDetention1.setTotalCount(productRecordDetention.getTotalCount());
                        sysProductRecordDetention1.setType(productRecordDetention.getType());
                        sysProductRecordDetention1.setCreateTime(productRecordDetention.getCreateTime());
                        sysProductRecordDetention1.setUpdateTime(productRecordDetention.getUpdateTime());
                        sysProductRecordDetention1.setStatus(productRecordDetention.getStatus());
                        sysProductRecordDetention1.setResult(productRecordDetention.isResult());
                        sysProductRecordDetention1.setProductRecordId(productRecordDetention.getProductRecordId());
                        sysProductRecordDetention1.setNum(productRecordDetention.getNum());
                        sysProductRecordDetention1.setNowNum(productRecordDetention.getNowNum());
                        sysProductRecordDetention1.setReason(productRecordDetention.getReason());
                        sysProductRecordDetention1.setMachineName(productRecordDetention.getMachineName());
                        sysProductRecordDetention1.setCreateUserId(productRecordDetention.getCreateUserId());
                        sysProductRecordDetention1.setCreateUserName(productRecordDetention.getCreateUserName());
                        sysProductRecordDetention1.setDataType(true);
                        sysProductRecordDetention1.setGroupName(productRecordDetention.getGroupName());
                        sysProductRecordDetention1.setMachineArea(productRecordDetention.getMachineArea());
                        sysProductRecordDetention1.setLineManager(productRecordDetention.getLineManager());
                        SysProductRecordDetentionRecord productRecordDetentionRecord = sysProductRecordDetentionRecordList.get(j);
                        SysProductRecordDetentionRecord productRecordDetentionRecord1 = new SysProductRecordDetentionRecord();
                        productRecordDetentionRecord1.setId(productRecordDetentionRecord.getId());
                        productRecordDetentionRecord1.setProductDate(productRecordDetentionRecord.getProductDate());
                        productRecordDetentionRecord1.setWorkPlanId(productRecordDetentionRecord.getWorkPlanId());
                        productRecordDetentionRecord1.setProductId(productRecordDetentionRecord.getProductId());
                        productRecordDetentionRecord1.setShortName(productRecordDetentionRecord.getShortName());
                        productRecordDetentionRecord1.setProductName(productRecordDetentionRecord.getProductName());
                        productRecordDetentionRecord1.setTotalCount(productRecordDetentionRecord.getTotalCount());
                        productRecordDetentionRecord1.setType(productRecordDetentionRecord.getType());
                        productRecordDetentionRecord1.setCreateTime(productRecordDetentionRecord.getCreateTime());
                        productRecordDetentionRecord1.setUpdateTime(productRecordDetentionRecord.getUpdateTime());
                        productRecordDetentionRecord1.setStatus(productRecordDetentionRecord.getStatus());
                        productRecordDetentionRecord1.setResult(productRecordDetentionRecord.isResult());
                        productRecordDetentionRecord1.setProductRecordId(productRecordDetentionRecord.getProductRecordId());
                        productRecordDetentionRecord1.setNum(productRecordDetentionRecord.getNum());
                        productRecordDetentionRecord1.setNowNum(productRecordDetentionRecord.getNowNum());
                        productRecordDetentionRecord1.setReason(productRecordDetentionRecord.getReason());
                        productRecordDetentionRecord1.setMachineName(productRecordDetentionRecord.getMachineName());
                        productRecordDetentionRecord1.setCreateUserId(productRecordDetentionRecord.getCreateUserId());
                        productRecordDetentionRecord1.setCreateUserName(productRecordDetentionRecord.getCreateUserName());
                        productRecordDetentionRecord1.setGroupName(productRecordDetention.getGroupName());
                        productRecordDetentionRecord1.setMachineArea(productRecordDetention.getMachineArea());
                        productRecordDetentionRecord1.setDataType(true);
                        productRecordDetentionRecord1.setLineManager(productRecordDetention.getLineManager());
                        if (j == 0) {
                            log.error("Product:{}", JSONObject.toJSONString(productRecordDetentionRecord));
                            productRecordDetentionRecord1.setEdit(true);
                            sysProductRecordDetention1.setNum(productRecordDetentionRecord.getNum());
                            sysProductRecordDetention1.setAdd(false);
                            sysProductRecordDetention1.setEdit(true);
                        } else {
                            productRecordDetentionRecord1.setParentIndex(productRecordDetentionList.size());
                            productRecordDetentionRecord1.setEdit(true);
                            sysProductRecordDetention1.setAdd(true);
                            sysProductRecordDetention1.setParentIndex(productRecordDetentionList.size());
                            sysProductRecordDetention1.setEdit(true);
                            sysProductRecordDetention1.setNum(productRecordDetentionRecord.getNum());
                        }

                        sysProductRecordDetention1.setProductRecordDetentionRecord(productRecordDetentionRecord1);

                        productRecordDetentionList1.add(sysProductRecordDetention1);


                    }

                    AtomicInteger total = new AtomicInteger();
                    productRecordDetentionList1.forEach(item -> {
                        total.addAndGet(item.getNum());
                    });
                    int cj = productRecordDetention.getTotalNum() - total.get();
                    if (cj > 0) {

                        SysProductRecordDetention sysProductRecordDetention1 = new SysProductRecordDetention();
                        sysProductRecordDetention1.setId(productRecordDetention.getId());
                        sysProductRecordDetention1.setProductDate(productRecordDetention.getProductDate());
                        sysProductRecordDetention1.setWorkPlanId(productRecordDetention.getWorkPlanId());
                        sysProductRecordDetention1.setProductId(productRecordDetention.getProductId());
                        sysProductRecordDetention1.setShortName(productRecordDetention.getShortName());
                        sysProductRecordDetention1.setProductName(productRecordDetention.getProductName());
                        sysProductRecordDetention1.setTotalCount(productRecordDetention.getTotalCount());
                        sysProductRecordDetention1.setType(productRecordDetention.getType());
                        sysProductRecordDetention1.setCreateTime(productRecordDetention.getCreateTime());
                        sysProductRecordDetention1.setUpdateTime(productRecordDetention.getUpdateTime());
                        sysProductRecordDetention1.setStatus(1);
                        sysProductRecordDetention1.setResult(productRecordDetention.isResult());
                        sysProductRecordDetention1.setProductRecordId(productRecordDetention.getProductRecordId());
                        sysProductRecordDetention1.setNum(productRecordDetention.getNum());
                        sysProductRecordDetention1.setNowNum(productRecordDetention.getNowNum());
                        sysProductRecordDetention1.setReason(productRecordDetention.getReason());
                        sysProductRecordDetention1.setMachineName(productRecordDetention.getMachineName());
                        sysProductRecordDetention1.setCreateUserId(productRecordDetention.getCreateUserId());
                        sysProductRecordDetention1.setCreateUserName(productRecordDetention.getCreateUserName());
                        sysProductRecordDetention1.setNum(cj);
                        sysProductRecordDetention1.setTotalNum(productRecordDetention.getTotalNum());
                        sysProductRecordDetention1.setAdd(true);
                        sysProductRecordDetention1.setEdit(true);
                        sysProductRecordDetention1.setParentIndex(productRecordDetentionList1.size() - 1);
                        sysProductRecordDetention1.setDataType(true);
                        sysProductRecordDetention1.setGroupName(productRecordDetention.getGroupName());
                        sysProductRecordDetention1.setMachineArea(productRecordDetention.getMachineArea());
                        sysProductRecordDetention1.setLineManager(productRecordDetention.getLineManager());
                        SysProductRecordDetentionRecord productRecordDetentionRecord = sysProductRecordDetentionRecordList.get(0);
                        SysProductRecordDetentionRecord productRecordDetentionRecord1 = new SysProductRecordDetentionRecord();


                        productRecordDetentionRecord1.setId(null);
                        productRecordDetentionRecord1.setProductDate(productRecordDetentionRecord.getProductDate());
                        productRecordDetentionRecord1.setWorkPlanId(productRecordDetentionRecord.getWorkPlanId());
                        productRecordDetentionRecord1.setProductId(productRecordDetentionRecord.getProductId());
                        productRecordDetentionRecord1.setShortName(productRecordDetentionRecord.getShortName());
                        productRecordDetentionRecord1.setProductName(productRecordDetentionRecord.getProductName());
                        productRecordDetentionRecord1.setTotalCount(productRecordDetentionRecord.getTotalCount());
                        productRecordDetentionRecord1.setType(productRecordDetentionRecord.getType());
                        productRecordDetentionRecord1.setCreateTime(productRecordDetentionRecord.getCreateTime());
                        productRecordDetentionRecord1.setUpdateTime(productRecordDetentionRecord.getUpdateTime());
                        productRecordDetentionRecord1.setStatus(productRecordDetentionRecord.getStatus());
                        productRecordDetentionRecord1.setResult(productRecordDetentionRecord.isResult());
                        productRecordDetentionRecord1.setProductRecordId(productRecordDetentionRecord.getProductRecordId());
                        productRecordDetentionRecord1.setNum(productRecordDetentionRecord.getNum());
                        productRecordDetentionRecord1.setNowNum(productRecordDetentionRecord.getNowNum());
                        productRecordDetentionRecord1.setReason(productRecordDetentionRecord.getReason());
                        productRecordDetentionRecord1.setMachineName(productRecordDetentionRecord.getMachineName());
                        productRecordDetentionRecord1.setCreateUserId(productRecordDetentionRecord.getCreateUserId());
                        productRecordDetentionRecord1.setCreateUserName(productRecordDetentionRecord.getCreateUserName());
                        productRecordDetentionRecord1.setEdit(false);
                        productRecordDetentionRecord1.setNum(0);
                        productRecordDetentionRecord1.setAdd(true);
                        productRecordDetentionRecord1.setType("良品");
                        productRecordDetentionRecord1.setDataType(true);
                        productRecordDetentionRecord1.setGroupName(productRecordDetention.getGroupName());
                        productRecordDetentionRecord1.setMachineArea(productRecordDetention.getMachineArea());
                        productRecordDetentionRecord1.setLineManager(productRecordDetention.getLineManager());
                        sysProductRecordDetention1.setProductRecordDetentionRecord(productRecordDetentionRecord1);
                        productRecordDetentionList1.add(sysProductRecordDetention1);
                    }
                    productRecordDetentionList.addAll(productRecordDetentionList1);
                } else {
                    if (productRecordDetention.getNum() > 0) {
                        productRecordDetention.setAdd(false);
                        productRecordDetention.setEdit(true);
                        productRecordDetentionList.add(productRecordDetention);
                    }

                }
            }
            log.error("ProList:{}", JSONObject.toJSONString(productRecordDetentionList));
        }
        return productRecordDetentionList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordDetentionList);
    }
   @PostMapping("/getProductRecordDetentionList1")
    public Result<?> getProductRecordDetentionList1(@RequestBody SysProductRecordDetention sysProductRecordDetention) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.GROUP_NAME.eq(sysProductRecordDetention.getGroupName()));
//        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.STATUS.ne(2));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.TOTAL_NUM.gt(0));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_ID.eq(sysProductRecordDetention.getProductId()));
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION.PRODUCT_DATE, true);
        List<SysProductRecordDetention> sysProductRecordDetentionList = this.sysProductRecordDetentionService.list(queryWrapper);
        List<SysProductRecordDetention> productRecordDetentionList = new ArrayList<>();
        if (!sysProductRecordDetentionList.isEmpty()) {
            for (SysProductRecordDetention productRecordDetention : sysProductRecordDetentionList) {
                //                    productRecordDetention.setEdit(false);
                queryWrapper = QueryWrapper.create();
//                    queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_ID.eq(productRecordDetention.getProductId()));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_RECORD_DETENTION_ID.eq(productRecordDetention.getId()));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION.GROUP_NAME.eq(sysProductRecordDetention.getGroupName()));
                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO.eq(fromDateToString("yyyy-MM-dd",sysProductRecordDetention.getProductDate())));
//                queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.SHIFT.eq(sysProductRecordDetention.getShift()));
//                    queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE.le(fromDateToString("yyyy-MM-dd", sysProductRecordDetention.getProductDate())));
//                    queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.MACHINE_NAME.eq(productRecordDetention.getMachineName()));
//                    queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.SHIFT.eq(productRecordDetention.getShift()));
                queryWrapper.orderBy(SYS_PRODUCT_RECORD_DETENTION_RECORD.CREATE_TIME, false);
                log.error("SQL:{}", queryWrapper.toSQL());
                List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordList = this.sysProductRecordDetentionRecordService.list(queryWrapper);
                if (sysProductRecordDetentionRecordList.size() > 0) {
                    List<SysProductRecordDetention> productRecordDetentionList1 = new ArrayList<>();
                    for (int j = 0; j < sysProductRecordDetentionRecordList.size(); j++) {
                        SysProductRecordDetention sysProductRecordDetention1 = new SysProductRecordDetention();
                        sysProductRecordDetention1.setId(productRecordDetention.getId());
                        sysProductRecordDetention1.setProductDate(productRecordDetention.getProductDate());
                        sysProductRecordDetention1.setWorkPlanId(productRecordDetention.getWorkPlanId());
                        sysProductRecordDetention1.setProductId(productRecordDetention.getProductId());
                        sysProductRecordDetention1.setShortName(productRecordDetention.getShortName());
                        sysProductRecordDetention1.setProductName(productRecordDetention.getProductName());
                        sysProductRecordDetention1.setTotalCount(productRecordDetention.getTotalCount());
                        sysProductRecordDetention1.setType(productRecordDetention.getType());
                        sysProductRecordDetention1.setCreateTime(productRecordDetention.getCreateTime());
                        sysProductRecordDetention1.setUpdateTime(productRecordDetention.getUpdateTime());
                        sysProductRecordDetention1.setStatus(productRecordDetention.getStatus());
                        sysProductRecordDetention1.setResult(productRecordDetention.isResult());
                        sysProductRecordDetention1.setProductRecordId(productRecordDetention.getProductRecordId());
                        sysProductRecordDetention1.setNum(productRecordDetention.getNum());
                        sysProductRecordDetention1.setNowNum(productRecordDetention.getNowNum());
                        sysProductRecordDetention1.setReason(productRecordDetention.getReason());
                        sysProductRecordDetention1.setMachineName(productRecordDetention.getMachineName());
                        sysProductRecordDetention1.setCreateUserId(productRecordDetention.getCreateUserId());
                        sysProductRecordDetention1.setCreateUserName(productRecordDetention.getCreateUserName());
                        sysProductRecordDetention1.setDataType(true);
                        sysProductRecordDetention1.setGroupName(productRecordDetention.getGroupName());
                        sysProductRecordDetention1.setMachineArea(productRecordDetention.getMachineArea());
                        SysProductRecordDetentionRecord productRecordDetentionRecord = sysProductRecordDetentionRecordList.get(j);
                        SysProductRecordDetentionRecord productRecordDetentionRecord1 = new SysProductRecordDetentionRecord();
                        productRecordDetentionRecord1.setId(productRecordDetentionRecord.getId());
                        productRecordDetentionRecord1.setProductDate(productRecordDetentionRecord.getProductDate());
                        productRecordDetentionRecord1.setWorkPlanId(productRecordDetentionRecord.getWorkPlanId());
                        productRecordDetentionRecord1.setProductId(productRecordDetentionRecord.getProductId());
                        productRecordDetentionRecord1.setShortName(productRecordDetentionRecord.getShortName());
                        productRecordDetentionRecord1.setProductName(productRecordDetentionRecord.getProductName());
                        productRecordDetentionRecord1.setTotalCount(productRecordDetentionRecord.getTotalCount());
                        productRecordDetentionRecord1.setType(productRecordDetentionRecord.getType());
                        productRecordDetentionRecord1.setCreateTime(productRecordDetentionRecord.getCreateTime());
                        productRecordDetentionRecord1.setUpdateTime(productRecordDetentionRecord.getUpdateTime());
                        productRecordDetentionRecord1.setStatus(productRecordDetentionRecord.getStatus());
                        productRecordDetentionRecord1.setResult(productRecordDetentionRecord.isResult());
                        productRecordDetentionRecord1.setProductRecordId(productRecordDetentionRecord.getProductRecordId());
                        productRecordDetentionRecord1.setNum(productRecordDetentionRecord.getNum());
                        productRecordDetentionRecord1.setNowNum(productRecordDetentionRecord.getNowNum());
                        productRecordDetentionRecord1.setReason(productRecordDetentionRecord.getReason());
                        productRecordDetentionRecord1.setMachineName(productRecordDetentionRecord.getMachineName());
                        productRecordDetentionRecord1.setCreateUserId(productRecordDetentionRecord.getCreateUserId());
                        productRecordDetentionRecord1.setCreateUserName(productRecordDetentionRecord.getCreateUserName());
                        productRecordDetentionRecord1.setGroupName(productRecordDetention.getGroupName());
                        productRecordDetentionRecord1.setMachineArea(productRecordDetention.getMachineArea());
                        productRecordDetentionRecord1.setDataType(true);
                        if (j == 0) {
                            log.error("Product:{}", JSONObject.toJSONString(productRecordDetentionRecord));
                            productRecordDetentionRecord1.setEdit(true);
                            sysProductRecordDetention1.setNum(productRecordDetentionRecord.getNum());
                            sysProductRecordDetention1.setAdd(false);
                            sysProductRecordDetention1.setEdit(true);
                        } else {
                            productRecordDetentionRecord1.setParentIndex(productRecordDetentionList.size());
                            productRecordDetentionRecord1.setEdit(true);
                            sysProductRecordDetention1.setAdd(true);
                            sysProductRecordDetention1.setParentIndex(productRecordDetentionList.size());
                            sysProductRecordDetention1.setEdit(true);
                            sysProductRecordDetention1.setNum(productRecordDetentionRecord.getNum());
                        }

                        sysProductRecordDetention1.setProductRecordDetentionRecord(productRecordDetentionRecord1);

                        productRecordDetentionList1.add(sysProductRecordDetention1);


                    }

                    AtomicInteger total = new AtomicInteger();
                    productRecordDetentionList1.forEach(item -> {
                        total.addAndGet(item.getNum());
                    });
                    int cj = productRecordDetention.getTotalNum() - total.get();
                    if (cj > 0) {

                        SysProductRecordDetention sysProductRecordDetention1 = new SysProductRecordDetention();
                        sysProductRecordDetention1.setId(productRecordDetention.getId());
                        sysProductRecordDetention1.setProductDate(productRecordDetention.getProductDate());
                        sysProductRecordDetention1.setWorkPlanId(productRecordDetention.getWorkPlanId());
                        sysProductRecordDetention1.setProductId(productRecordDetention.getProductId());
                        sysProductRecordDetention1.setShortName(productRecordDetention.getShortName());
                        sysProductRecordDetention1.setProductName(productRecordDetention.getProductName());
                        sysProductRecordDetention1.setTotalCount(productRecordDetention.getTotalCount());
                        sysProductRecordDetention1.setType(productRecordDetention.getType());
                        sysProductRecordDetention1.setCreateTime(productRecordDetention.getCreateTime());
                        sysProductRecordDetention1.setUpdateTime(productRecordDetention.getUpdateTime());
                        sysProductRecordDetention1.setStatus(1);
                        sysProductRecordDetention1.setResult(productRecordDetention.isResult());
                        sysProductRecordDetention1.setProductRecordId(productRecordDetention.getProductRecordId());
                        sysProductRecordDetention1.setNum(productRecordDetention.getNum());
                        sysProductRecordDetention1.setNowNum(productRecordDetention.getNowNum());
                        sysProductRecordDetention1.setReason(productRecordDetention.getReason());
                        sysProductRecordDetention1.setMachineName(productRecordDetention.getMachineName());
                        sysProductRecordDetention1.setCreateUserId(productRecordDetention.getCreateUserId());
                        sysProductRecordDetention1.setCreateUserName(productRecordDetention.getCreateUserName());
                        sysProductRecordDetention1.setNum(cj);
                        sysProductRecordDetention1.setTotalNum(productRecordDetention.getTotalNum());
                        sysProductRecordDetention1.setAdd(true);
                        sysProductRecordDetention1.setEdit(true);
                        sysProductRecordDetention1.setParentIndex(productRecordDetentionList1.size() - 1);
                        sysProductRecordDetention1.setDataType(true);
                        sysProductRecordDetention1.setGroupName(productRecordDetention.getGroupName());
                        sysProductRecordDetention1.setMachineArea(productRecordDetention.getMachineArea());
                        SysProductRecordDetentionRecord productRecordDetentionRecord = sysProductRecordDetentionRecordList.get(0);
                        SysProductRecordDetentionRecord productRecordDetentionRecord1 = new SysProductRecordDetentionRecord();


                        productRecordDetentionRecord1.setId(null);
                        productRecordDetentionRecord1.setProductDate(productRecordDetentionRecord.getProductDate());
                        productRecordDetentionRecord1.setWorkPlanId(productRecordDetentionRecord.getWorkPlanId());
                        productRecordDetentionRecord1.setProductId(productRecordDetentionRecord.getProductId());
                        productRecordDetentionRecord1.setShortName(productRecordDetentionRecord.getShortName());
                        productRecordDetentionRecord1.setProductName(productRecordDetentionRecord.getProductName());
                        productRecordDetentionRecord1.setTotalCount(productRecordDetentionRecord.getTotalCount());
                        productRecordDetentionRecord1.setType(productRecordDetentionRecord.getType());
                        productRecordDetentionRecord1.setCreateTime(productRecordDetentionRecord.getCreateTime());
                        productRecordDetentionRecord1.setUpdateTime(productRecordDetentionRecord.getUpdateTime());
                        productRecordDetentionRecord1.setStatus(productRecordDetentionRecord.getStatus());
                        productRecordDetentionRecord1.setResult(productRecordDetentionRecord.isResult());
                        productRecordDetentionRecord1.setProductRecordId(productRecordDetentionRecord.getProductRecordId());
                        productRecordDetentionRecord1.setNum(productRecordDetentionRecord.getNum());
                        productRecordDetentionRecord1.setNowNum(productRecordDetentionRecord.getNowNum());
                        productRecordDetentionRecord1.setReason(productRecordDetentionRecord.getReason());
                        productRecordDetentionRecord1.setMachineName(productRecordDetentionRecord.getMachineName());
                        productRecordDetentionRecord1.setCreateUserId(productRecordDetentionRecord.getCreateUserId());
                        productRecordDetentionRecord1.setCreateUserName(productRecordDetentionRecord.getCreateUserName());
                        productRecordDetentionRecord1.setEdit(false);
                        productRecordDetentionRecord1.setNum(0);
                        productRecordDetentionRecord1.setAdd(true);
                        productRecordDetentionRecord1.setType("良品");
                        productRecordDetentionRecord1.setDataType(true);
                        productRecordDetentionRecord1.setGroupName(productRecordDetention.getGroupName());
                        productRecordDetentionRecord1.setMachineArea(productRecordDetention.getMachineArea());
                        sysProductRecordDetention1.setProductRecordDetentionRecord(productRecordDetentionRecord1);
                        productRecordDetentionList1.add(sysProductRecordDetention1);
                    }
                    productRecordDetentionList.addAll(productRecordDetentionList1);
                } else {
                    if (productRecordDetention.getNum() > 0) {
                        productRecordDetention.setAdd(false);
                        productRecordDetention.setEdit(true);
                        productRecordDetentionList.add(productRecordDetention);
                    }

                }
            }
            log.error("ProList:{}", JSONObject.toJSONString(productRecordDetentionList));
        }
        return productRecordDetentionList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordDetentionList);
    }


}
